package cn.jinjimi.app.main.adapter.recycler;

import android.animation.Animator;
import android.animation.ObjectAnimator;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import cn.jinjimi.app.R;
import cn.jinjimi.app.entity.LinkBean;
import cn.jinjimi.app.main.widget.FrescoImageView.FrescoImageView;

/**
 * Created by Roy
 * Date: 15/9/29
 */
public class HomeHeadToolAdaptar extends MyBaseRecyclerAdapter<LinkBean, HomeHeadToolAdaptar.ViewHolder> {

    private Context mContext;

    private boolean flag;

    public onActionClickListener onActionClickListener;

    public void setOnActionClickListener(onActionClickListener onActionClickListener) {
        this.onActionClickListener = onActionClickListener;
    }

    public interface onActionClickListener {
        void onItemClick(LinkBean data, int position);
    }

    public HomeHeadToolAdaptar(Context context) {
        this.mContext = context;
    }

    @Override
    protected Animator[] getAnimators(View view) {
        return new Animator[]{ObjectAnimator.ofFloat(view, "alpha", 0f, 1f)};
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new ViewHolder(LayoutInflater.from(mContext).inflate(R.layout.item_home_tool_layout, parent, false));
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        super.onBindViewHolder(holder, position);

        LinkBean item = getItem(position);
        holder.setData(item);
    }

    class ViewHolder extends MyBaseRecyclerAdapter.MyViewHolder {
        public LinearLayout llTool;
        public FrescoImageView icon;
        public TextView tvTitle;

        public ViewHolder(View view) {
            super(view);
            llTool = (LinearLayout) view.findViewById(R.id.ll_tool);
            icon = (FrescoImageView) view.findViewById(R.id.home_tool_icon);
            tvTitle = (TextView) view.findViewById(R.id.home_tool_title);
        }

        public void setData(final LinkBean data) {
            icon.loadView(data.img);

            tvTitle.setText(data.label);

            llTool.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (onActionClickListener != null)
                        onActionClickListener.onItemClick(data, getHolderPosition());
                }
            });
        }
    }
}
